package net.oschina.app.improve.detail.fragments;

import net.oschina.app.R;
import net.oschina.app.fragment.EventDetailFragment;
import net.oschina.app.improve.detail.activities.EventDetailActivity;
import net.oschina.app.improve.detail.fragments.MySetTimerActivity;
import net.oschina.app.service.NoticeUtils;
import net.oschina.app.ui.MainActivity;
import net.oschina.app.util.TLog;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.widget.Toast;

/**
 * Created by DCL on 2016/11/29.
 */
public class AlarmRecieverMyself extends BroadcastReceiver {
    private NotificationManager nm;
    private PendingIntent pd;

    @Override
    public void onReceive(Context context, Intent intent) {
        //Log.d(MainActivity.TAG, "the time is up,start the alarm...")

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.notification_icon)
                        .setContentTitle("您有一个活动需要注意！！")
                        .setDefaults(Notification.DEFAULT_SOUND)
                        .setContentText(intent.getStringExtra("wordNeedShow"));

        Intent resultIntent = new Intent(context, MainActivity.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        stackBuilder.addParentStack(MainActivity.class);

        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        android.app.NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        int mId = 1;
        Notification mBui = mBuilder.build();
        mNotificationManager.notify(mId, mBui);

        Toast.makeText(context, "你有一个活动将要开始！！！", Toast.LENGTH_SHORT).show();

    }
}
